package com.ruoyi.web.controller.supermarket;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.supermarket.domain.SupermarketComShelf;
import com.ruoyi.supermarket.domain.SupermarketShelf;
import com.ruoyi.supermarket.service.ISupermarketComShelfService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.List;

/**
 * 超市货架信息Controller
 * 
 * @author faye
 * @date 2024-05-28
 */
@RestController
@RequestMapping("/supermarket/storage")
public class SupermarketComShelfController extends BaseController
{
    @Autowired
    private ISupermarketComShelfService supermarketComShelfService;

    /**
     * 查询超市货架信息列表
     */
    @PreAuthorize("@ss.hasPermi('supermarket:storage:list')")
    @GetMapping("/list")
    public TableDataInfo list(SupermarketComShelf supermarketComShelf)
    {
        startPage();
        List<SupermarketComShelf> list = supermarketComShelfService.selectSupermarketComShelfList(supermarketComShelf);
        return getDataTable(list);
    }

//    @GetMapping("/listShelf")
//    public AjaxResult listShelf(Long commodityId)
//    {
//        List<SupermarketShelf> supermarketShelves=supermarketComShelfService.selectShelfByComId(commodityId);
//        List<String> listLoc=new ArrayList<>();
//        for(SupermarketShelf shelf:supermarketShelves){
//            listLoc.add(shelf.getShelfLocation());
//        }
//
//        return success(listLoc);
//    }


    /**
     * 导出超市货架信息列表
     */
    @PreAuthorize("@ss.hasPermi('supermarket:storage:export')")
    @Log(title = "超市货架信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SupermarketComShelf supermarketComShelf)
    {
        List<SupermarketComShelf> list = supermarketComShelfService.selectSupermarketComShelfList(supermarketComShelf);
        ExcelUtil<SupermarketComShelf> util = new ExcelUtil<SupermarketComShelf>(SupermarketComShelf.class);
        util.exportExcel(response, list, "超市货架信息数据");
    }

    /**
     * 获取超市货架信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('supermarket:storage:query')")
    @GetMapping(value = "/{storageId}")
    public AjaxResult getInfo(@PathVariable("storageId") Long storageId)
    {
        return success(supermarketComShelfService.selectSupermarketComShelfByStorageId(storageId));
    }

    /**
     * 新增超市货架信息
     */
    @PreAuthorize("@ss.hasPermi('supermarket:storage:add')")
    @Log(title = "超市货架信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SupermarketComShelf supermarketComShelf)
    {
        return toAjax(supermarketComShelfService.insertSupermarketComShelf(supermarketComShelf));
    }

    /**
     * 修改超市货架信息
     */
    @PreAuthorize("@ss.hasPermi('supermarket:storage:edit')")
    @Log(title = "超市货架信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SupermarketComShelf supermarketComShelf)
    {
        return toAjax(supermarketComShelfService.updateSupermarketComShelf(supermarketComShelf));
    }

    /**
     * 删除超市货架信息
     */
    @PreAuthorize("@ss.hasPermi('supermarket:storage:remove')")
    @Log(title = "超市货架信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{storageIds}")
    public AjaxResult remove(@PathVariable Long[] storageIds)
    {
        return toAjax(supermarketComShelfService.deleteSupermarketComShelfByStorageIds(storageIds));
    }
}
